import { getToken, setToken, removeToken } from '@/utils/auth.js'
export default {
	namespaced: true,
	state: {
		isLogin: false,
		app: {
			  platform: ''
		}		
	},
	mutations: {
		SET_IS_LOGIN(state, b) {
			state.isLogin = b
		},
		SET_APP_PLATFORM(state, s) {
			state.app.platform = s
		}
	},
	actions: {
		initApp({dispatch,commit,state}) {
			// #ifdef MP-WEIXIN
			commit('SET_APP_PLATFORM', 'MP-WEIXIN')
			// #endif
			let token = getToken()
			if(token){
				dispatch('user/getUserInfo',{},{root:true})
			}else{
				uni.login({
					success(res) {
						console.log(res.code,'用户 code')
						dispatch('auth/login',{}, { root: true })
					}
				})				
			}						
		}
	}
}